<template>
    <div class="mainDiv">
        <el-row :gutter="20" class="rowHead">
            <el-col :span="10" class="flex_center">
                <el-button type="success" icon="plus" @click="addbrand" v-qx="permission.add" style="margin-right: 5px;">新增品牌</el-button>
                <el-select v-model="page.zt" class="ml" @change="selstatus" v-qx="permission.status">
                    <el-option v-for="(s, k) in status" :label="s.txt" :value="s.val" :key="s.val">
                    </el-option>
                </el-select>
            </el-col>
            <el-col :span="14" class="flex_end_center">
                <el-input class="searchArea" placeholder="搜索品牌名称、品牌描述" @keyup.enter.native="searchList" v-model="page.search">
                    <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="searchList"></i>
                </el-input>
                <el-button type="primary" icon="h-shuaxin1" class="buttonLeft" @click="searchList">刷新列表</el-button>
            </el-col>
        </el-row>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="id" label="ID" width="100"></el-table-column>
            <el-table-column prop="name" label="品牌名称"></el-table-column>
            <el-table-column prop="remarks" label="品牌描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="isdisabled" label="状态">
                <template slot-scope="scope">
                    <Tags :typeValue="scope.row.isdisabled" typeName="isDisable"></Tags>
                </template>
            </el-table-column>
            <el-table-column prop="fname" label="所属厂商"></el-table-column>
            <el-table-column prop="addtime" label="添加日期">
                <template slot-scope="scope">
                    {{scope.row.addtime|hourTime}}
                </template>
            </el-table-column>
            <el-table-column label="品牌操作">
                <template slot-scope="scope">
                    <el-button-group v-if="!scope.row.isdisabled">
                        <el-tooltip content="品牌编辑" placement="left" :open-delay="800" v-qx="permission.edit">
                            <el-button type="warning" icon="el-icon-edit" size="mini" @click="edit(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="停用品牌" placement="top" :open-delay="800" v-qx="permission.unstop">
                            <el-button type="danger" icon="el-icon-h-jinyong" size="mini" @click="stop(scope.row.id,1)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                    <el-tooltip content="重新开启品牌" placement="left" :open-delay="800" v-else v-qx="permission.unstop">
                        <el-button type="success" icon="el-icon-h-qiyong2" size="mini" @click="stop(scope.row.id,0)"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
import Brand from '@/service/organization/brand.js'
import Tags from '@/components/orderTags.vue'

export default {
  name: 'brandList',
  data () {
    return {
      list: [],
      total: 0,
      page: {
        pages: 1,
        limits: 15,
        search: '',
        zt: 0
      },
      status: [{
        txt: '正常',
        val: 0
      }, {
        txt: '停用',
        val: 1
      }],
      permission: {
        add: 'brand_add',
        status: 'brand_status',
        edit: 'brand_edit',
        unstop: 'brand_unstop'
      }
    }
  },
  methods: {
    addbrand: async function () {
      let res = await Brand.openAddBrand()
      if (res && res.data) {
        C.success(res.data)
        this.getList()
      }
    },
    edit: async function (row) {
      let res = await Brand.openAddBrand(row)
      if (res && res.data) {
        C.success(res.data)
        this.getList()
      }
    },
    stop: function (id, st) {
      let that = this
      let str = st ? '停用机构品牌, 是否继续?' : '重新启用之后若被店家拉取走，将不能再次对该品牌进行修改'
      C.confirm(str, async () => {
        let res = await C.ajax('/organization/brand/brandstatus', { id: id, st: st }, 'post')
        if (res) {
          that.getList()
          C.success(res.data)
        }
      })
    },
    selstatus: function () {
      this.getList()
    },
    sizeChange: function (val) {
      this.page.limits = val
      this.getList()
    },
    currentChange: function (val) {
      this.page.pages = val
      this.getList()
    },
    searchList: function () {
      this.getList()
    },
    getList: async function (nums, limits, searchStr) {
      let that = this
      let data = await C.ajax('/organization/brand/brandlist', this.page, 'post')
      if (data) {
        that.list = data.data
        that.total = data.count
      }
    }
  },
  mounted: function () {
    this.getList()
  },
  components: { Tags }
}
</script>